﻿using System.Collections.Generic;
using YAXLib;

namespace RaytracerLib.Volumes
{
    public abstract class BinaryVolume : Volume
    {
        private Volume m_child_volume1;
        private Volume m_child_volume2;

        protected BinaryVolume(Volume a_childVolume1, Volume a_childVolume2)
        {
            ChildVolume1 = a_childVolume1;
            ChildVolume2 = a_childVolume2;
        }

        public override IEnumerable<Volume> Children
        {
            get
            {
                yield return ChildVolume1;
                yield return ChildVolume2;
            }
        }

        [YAXNode("Volume1")]
        public Volume ChildVolume1
        {
            get
            {
                return m_child_volume1;
            }
            set
            {
                if (m_child_volume1 != null)
                    m_child_volume1.Parent = null;
                m_child_volume1 = value;
                if (m_child_volume1 != null)
                    m_child_volume1.Parent = this;
            }
        }

        [YAXNode("Volume2")]
        public Volume ChildVolume2
        {
            get
            {
                return m_child_volume2;
            }
            set
            {
                if (m_child_volume2 != null)
                    m_child_volume2.Parent = null;
                m_child_volume2 = value;
                if (m_child_volume1 != null)
                    m_child_volume2.Parent = this;
            }
        }
    }
}